package com.mach.platform.repository;

import com.mach.platform.domain.iot.IotDevConfiguration;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author Anonymous
 * @Description:
 * @Package: com.mach.platform.repository
 * @time 2018/05/06 12:50
 */
@Repository
public interface IotDevConfigRepository extends BaseRepository<IotDevConfiguration> {

	/**
	 * 查找分页数据
	 * @param searchParam
	 * @param pageable
	 * @return
	 */
	@Query(value = "select TT.label, TT.uuid from (select distinct label,uuid from dev_config where label like concat('%',?1,'%') or uuid like concat('%',?1,'%')) TT", countQuery = "select count(*) from (select distinct label,uuid from dev_config where label like concat('%',?1,'%') or uuid like concat('%',?1,'%')) TT", nativeQuery = true)
	Page<Map> loadDevConfigPageData (String searchParam, Pageable pageable);

	/**
	 * 删除对应的设备ID 和 uuid的数据
	 * @param uuid
	 * @return
	 */
	@Modifying
	int deleteAllByUuid (String uuid);

	/**
	 * 根据 对应的 uuid 获取对应的数据
	 * @param uuid
	 * @return
	 */
	List<IotDevConfiguration> findAllByUuidOrderBySortAsc(String uuid);

}
